/*     */ package com.zimbra.cs.ldap;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.ldap.unboundid.InMemoryLdapServer;
/*     */ import com.zimbra.cs.ldap.unboundid.InMemoryLdapServer.ServerConfig;
/*     */ import com.zimbra.cs.ldap.unboundid.UBIDLdapClient;
/*     */ import com.zimbra.cs.util.Zimbra;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class LdapClient
/*     */ {
/*     */   private static LdapClient ldapClient;
/*  36 */   private static boolean ALWAYS_USE_MASTER = false;
/*     */   
/*     */   static synchronized LdapClient getInstance() {
/*  39 */     if (ldapClient == null)
/*     */     {
/*  41 */       if (InMemoryLdapServer.isOn()) {
/*     */         try {
/*  43 */           InMemoryLdapServer.start("ZIMBRA_LDAP_SERVER", new InMemoryLdapServer.ServerConfig(Lists.newArrayList(new String[] { "dc=unittest" })));
/*     */         }
/*     */         catch (Exception e)
/*     */         {
/*  47 */           ZimbraLog.system.error("could not start InMemoryLdapServer", e);
/*     */         }
/*     */       }
/*     */       
/*  51 */       String className = LC.zimbra_class_ldap_client.value();
/*  52 */       if ((className != null) && (!className.equals(""))) {
/*     */         try {
/*  54 */           ldapClient = (LdapClient)Class.forName(className).newInstance();
/*     */         } catch (Exception e) {
/*  56 */           ZimbraLog.system.error("could not instantiate LDAP client '" + className + "'; defaulting to JNDI LDAP SDK", e);
/*     */         }
/*     */       }
/*     */       
/*  60 */       if (ldapClient == null) {
/*  61 */         ldapClient = new UBIDLdapClient();
/*     */       }
/*     */       try
/*     */       {
/*  65 */         ldapClient.init(ALWAYS_USE_MASTER);
/*     */       } catch (LdapException e) {
/*  67 */         Zimbra.halt("failed to initialize LDAP client", e);
/*     */       }
/*     */     }
/*  70 */     return ldapClient;
/*     */   }
/*     */   
/*     */   private static synchronized void unsetInstance() {
/*  74 */     ldapClient = null;
/*     */   }
/*     */   
/*     */   public static synchronized void masterOnly()
/*     */   {
/*  79 */     ALWAYS_USE_MASTER = true;
/*     */     
/*  81 */     if (ldapClient != null)
/*     */     {
/*  83 */       ldapClient.alwaysUseMaster();
/*     */     }
/*     */   }
/*     */   
/*     */   public static void initialize() {
/*  88 */     getInstance();
/*     */   }
/*     */   
/*     */   public static void shutdown()
/*     */   {
/*  93 */     getInstance().terminate();
/*  94 */     unsetInstance();
/*     */   }
/*     */   
/*     */ 
/*     */   public static ZLdapContext toZLdapContext(Provisioning prov, ILdapContext ldapContext)
/*     */   {
/* 100 */     if (!(getInstance() instanceof UBIDLdapClient)) {
/* 101 */       Zimbra.halt("LdapClient instance is not UBIDLdapClient", ServiceException.FAILURE("internal error, wrong ldap context instance", null));
/*     */     }
/*     */     
/*     */ 
/*     */ 
/* 106 */     if ((ldapContext != null) && (!(ldapContext instanceof ZLdapContext))) {
/* 107 */       Zimbra.halt("ILdapContext instance is not ZLdapContext", ServiceException.FAILURE("internal error, wrong ldap context instance", null));
/*     */     }
/*     */     
/*     */ 
/* 111 */     return (ZLdapContext)ldapContext;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void waitForLdapServer()
/*     */   {
/* 121 */     getInstance().waitForLdapServerImpl();
/*     */   }
/*     */   
/*     */   public static ZLdapContext getContext(LdapUsage usage) throws ServiceException {
/* 125 */     return getContext(LdapServerType.REPLICA, usage);
/*     */   }
/*     */   
/*     */   public static ZLdapContext getContext(LdapServerType serverType, LdapUsage usage) throws ServiceException
/*     */   {
/* 130 */     return getInstance().getContextImpl(serverType, usage);
/*     */   }
/*     */   
/*     */   public static ZLdapContext getContext(LdapServerType serverType, boolean useConnPool, LdapUsage usage)
/*     */     throws ServiceException
/*     */   {
/* 136 */     return getInstance().getContextImpl(serverType, useConnPool, usage);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static ZLdapContext getContext(LdapServerConfig.GenericLdapConfig ldapConfig, LdapUsage usage)
/*     */     throws ServiceException
/*     */   {
/* 163 */     return getInstance().getExternalContextImpl(ldapConfig, usage);
/*     */   }
/*     */   
/*     */   public static ZLdapContext getExternalContext(LdapServerConfig.ExternalLdapConfig ldapConfig, LdapUsage usage)
/*     */     throws ServiceException
/*     */   {
/* 169 */     return getInstance().getExternalContextImpl(ldapConfig, usage);
/*     */   }
/*     */   
/*     */   public static void closeContext(ZLdapContext lctxt) {
/* 173 */     if (lctxt != null) {
/* 174 */       lctxt.closeContext(false);
/*     */     }
/*     */   }
/*     */   
/*     */   public static ZMutableEntry createMutableEntry() {
/* 179 */     return getInstance().createMutableEntryImpl();
/*     */   }
/*     */   
/*     */   public static void externalLdapAuthenticate(String[] urls, boolean wantStartTLS, String bindDN, String password, String note)
/*     */     throws ServiceException
/*     */   {
/* 185 */     getInstance().externalLdapAuthenticateImpl(urls, wantStartTLS, bindDN, password, note);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void zimbraLdapAuthenticate(String bindDN, String password)
/*     */     throws ServiceException
/*     */   {
/* 200 */     getInstance().zimbraLdapAuthenticateImpl(bindDN, password);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   protected void init(boolean alwaysUseMaster)
/*     */     throws LdapException
/*     */   {
/* 209 */     ZSearchScope.init(getSearchScopeFactoryInstance());
/* 210 */     ZLdapFilterFactory.setInstance(getLdapFilterFactoryInstance());
/*     */   }
/*     */   
/*     */   protected abstract void terminate();
/*     */   
/*     */   protected abstract void alwaysUseMaster();
/*     */   
/*     */   protected abstract ZSearchScope.ZSearchScopeFactory getSearchScopeFactoryInstance();
/*     */   
/*     */   protected abstract ZLdapFilterFactory getLdapFilterFactoryInstance()
/*     */     throws LdapException;
/*     */   
/*     */   protected abstract void waitForLdapServerImpl();
/*     */   
/*     */   protected abstract ZLdapContext getContextImpl(LdapServerType paramLdapServerType, LdapUsage paramLdapUsage)
/*     */     throws ServiceException;
/*     */   
/*     */   protected abstract ZLdapContext getContextImpl(LdapServerType paramLdapServerType, boolean paramBoolean, LdapUsage paramLdapUsage)
/*     */     throws ServiceException;
/*     */   
/*     */   protected abstract ZLdapContext getExternalContextImpl(LdapServerConfig.ExternalLdapConfig paramExternalLdapConfig, LdapUsage paramLdapUsage)
/*     */     throws ServiceException;
/*     */   
/*     */   protected abstract ZMutableEntry createMutableEntryImpl();
/*     */   
/*     */   protected abstract ZSearchControls createSearchControlsImpl(ZSearchScope paramZSearchScope, int paramInt, String[] paramArrayOfString);
/*     */   
/*     */   protected abstract void externalLdapAuthenticateImpl(String[] paramArrayOfString, boolean paramBoolean, String paramString1, String paramString2, String paramString3)
/*     */     throws ServiceException;
/*     */   
/*     */   protected abstract void zimbraLdapAuthenticateImpl(String paramString1, String paramString2)
/*     */     throws ServiceException;
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/ldap/LdapClient.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */